package com.fanshuai.net;

import org.springframework.web.socket.WebSocketSession;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SpringWebChatManager {
    public static Map<String, WebSocketSession> sessionMap = new ConcurrentHashMap<>();

    public static void addConnection(WebSocketSession session, String uid) {
        sessionMap.put(uid, session);
    }

    public static void delConnection(String uid) {
        sessionMap.remove(uid);
    }

    public static String getUid(WebSocketSession session) {
        for (String uid : sessionMap.keySet()) {
            WebSocketSession session1 = sessionMap.get(uid);
            if (session1.getId().equals(session.getId())) {
                return uid;
            }
        }

        return "";
    }
}
